package com.xz.sanitize.config;

import com.xz.sanitize.serializer.NullAwareBeanSerializerModifier;
import com.xz.sanitize.strategy.BuiltinDefaultValueProvider;
import com.xz.sanitize.strategy.DefaultValueProvider;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 注册用于实现空值转默认值清理的Jackson模块。
 */
@Configuration
public class JacksonSanitizeConfig {
    @Bean
    public DefaultValueProvider defaultValueProvider() {
        return new BuiltinDefaultValueProvider();
    }

    @Bean
    public Module sanitizeModule(DefaultValueProvider provider) {
        SimpleModule module = new SimpleModule("sanitize-module");
        module.setSerializerModifier(new NullAwareBeanSerializerModifier(provider));
        return module;
    }
}
